<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of shippingcom_model
 *
 * @author hassanali
 */
class statues_model extends admin_model{
    //put your code here
    public function __construct() {
        parent::__construct();
    }
    
        public function filter($nolimit = false) {
        /* ======== filter ======== */
        
        $statrt_limit = get_segment(4, 0);
        if ($nolimit == false) {
            $this->db->limit(10, $statrt_limit);
        }


        $this->db->select('users.username ,statues.* ', false);
        $this->db->order_by('statues.id ' . metohd_get_uri('sort', 'desc'));
        $this->db->join('users ', 'users.id=statues.user_id');
        $this->db->from('statues');


        $sql = $this->db->get();

        return $sql->result();
    }

    public function update($user_data,$id) {
        $user_data['user_update'] = $this->admin_id;
        $user_data['update_date'] = date('Y-m-d H:i:s');
        
        $this->db->update('statues', $user_data, array('id' => $id));
        
        // add report
        $user_data['id']=$this->db->insert_id();
        $this->add_manager_report(array('action' => 'statues-edit', 'contant' =>$user_data));
    }


    public function delete($id, $where = '') {
        
        $this->is_used_in_order($id);
        
        if (count($id) > 0) {
            $this->db->where_in('id', $id);
        }
        
        $this->db->delete('statues', $where);
        
        if(is_array($id)){
           $admin_id=join(',',$id); 
        }else{
          $admin_id= $id; 
        }
        
        $this->add_manager_report(array('action' => 'statues-delete', 'contant' =>$admin_id ));
    }


    
    public function save($data){

        $data['create_date']=date('Y-m-d H:i:s');
        $this->db->insert('statues',$data); 
        
        // add report
        $data['id']=$this->db->insert_id();
        $this->add_manager_report(array('action' => 'statues-add', 'contant' =>$data));
    }
    
    public function is_used_in_order($id,$where=array()){
        
        if(count($id) > 0){
           $this->db->where_in('statue_id',$id);
        }else{
          $this->db->where('statue_id',$id);  
        }
        
        $this->db->limit(1);
        $sql=$this->db->get_where('items',$where);
        if($sql->num_rows()){
          $this->themes->set_message(array('url' => 'statues/', 'type' => 'error', 'message' => '{{Catnot Delete Its Used in Another Palce }}'));  
        }
    }
    
}

?>
